package com.mfin.bom.adapter;

import com.mfin.bom.interfaces.ICustomer;
import com.mfin.bom.interfaces.IFinance;
import com.mfin.bom.interfaces.IPartner;
import com.mfin.bom.objects.Partner;
import com.mfin.vo.ObjectKey;

public class PartnerAdapter extends IIdentifiableAdapter implements IPartner {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6931847662509590705L;

	Partner wrappedPartner;

	public PartnerAdapter(Partner p, ObjectKey[] keys) {
		wrappedPartner = p;
		ObjectKey[] newKeys = new ObjectKey[2];
		newKeys[0] = keys[0];
		newKeys[1] = new ObjectKey(wrappedPartner.getId());
		setKeys(newKeys);
	}
	
	@Override
	public Long getPartnerId() {
		return wrappedPartner.getId();
	}

	@Override
	public void setPartnerId(Long id) {
		wrappedPartner.setId(id);
	}

	@Override
	public ICustomer getCustomer() {
		return new CustomerAdapter(wrappedPartner.getCustomer(), getKeys());
	}

	@Override
	public void setCustomer(ICustomer bomCustomer) {
		if (bomCustomer != null) {
			CustomerAdapter customerAdapter = (CustomerAdapter) bomCustomer;
			wrappedPartner.setCustomer(customerAdapter
					.getCustomer());
		}
	}

	@Override
	public IFinance getFinance() {
		return new FinanceAdapter(wrappedPartner.getFinance());
	}

	@Override
	public void setFinance(IFinance bomFinanceInformation) {
		if (bomFinanceInformation != null) {
			FinanceAdapter financeInformationAdapter = (FinanceAdapter) bomFinanceInformation;
			wrappedPartner.setFinance(financeInformationAdapter
					.getFinance());
		}
	}

	public Partner getPartner() {
		return wrappedPartner;
	}
}
